<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 *
 * */

class BasketItem{
    private $id;
    private $product_id;
    private $count;
    private $product;
    
    private function load(){
        $this->product = ProductTable::getInstance()->findOneBy('id', $this->product_id);
        if(!$this->product){
            throw new Exception('Cannot find product.');
        }
    }
    
    public function __construct($id, $prod, $prod_count){
        $this->id = $id;
        $this->product_id = $prod;
        $this->count = $prod_count;
        $this->load();
    }
    
    public function getOwnId(){
        return $this->id;
    }
    
    public function getProduct(){
        return $this->product;
    }
    
    public function getCount(){
        return $this->count;
    }
    
    public function getValue(){
        return $this->product->getPrice() * $this->count();
    }
}